import { getImage, checkVerifyCode } from '@/services/verifyCode'

export default {
    namespace: 'verify_code',
    state: {
        image: ''
    },
    effects: {
        *getImage (_, { call, put }) {
            const result = yield call(getImage);
            yield put({
                type: 'changeState',
                result,
                field: 'image'
            })
            return {
                status: result.status,
                message: result.message
            }
        },

        *checkVerifyCode ({ code }, { call }) {
            const result = yield call(checkVerifyCode, { code })
            return {
                status: result.status,
                message: result.message
            }
        },
    },
    reducers: {
        changeState(state, { result, field }) {
            const nextState = JSON.parse(JSON.stringify({ data: state })).data
            nextState[field] = result
            return nextState
        }
    }
}